unit UserUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, GridsEh, DBGridEh, DB, ADODB, Menus;

type
  TfrmUser = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    edtUserName: TEdit;
    Label2: TLabel;
    edtUserId: TEdit;
    Label3: TLabel;
    edtIP: TEdit;
    btnSearch: TButton;
    dbgUser: TDBGridEh;
    Query: TADOQuery;
    QueryUserId: TAutoIncField;
    QueryUserNum: TIntegerField;
    QueryUsername: TWideStringField;
    QueryUserPassword: TWideStringField;
    QueryUserBrand: TIntegerField;
    QueryUserProduct: TIntegerField;
    QueryUserType: TIntegerField;
    QueryUserArea: TIntegerField;
    QueryUserConnection: TIntegerField;
    QueryUserClientNums: TIntegerField;
    QueryUserLevel: TIntegerField;
    QueryUserAroundType: TIntegerField;
    QueryUserHardInfo: TWideStringField;
    QueryUserPort: TIntegerField;
    QueryUserActive: TIntegerField;
    QueryUserEnable: TIntegerField;
    QueryUserAdmin: TIntegerField;
    QueryUserUsefulTime: TDateTimeField;
    QueryUserADPartner: TIntegerField;
    QueryUserContact: TWideStringField;
    QueryUserAddress: TWideStringField;
    QueryUserPhone: TWideStringField;
    QueryUserCellPhone: TWideStringField;
    QueryUserPoint: TIntegerField;
    QueryUpdateTime: TDateTimeField;
    QueryUserAuthKey: TWideStringField;
    QueryUserIp: TWideStringField;
    QueryUserSeed: TIntegerField;
    QueryMemo: TWideStringField;
    DataSource1: TDataSource;
    pmUser: TPopupMenu;
    nClearHardinfo: TMenuItem;
    nADPartner: TMenuItem;
    nNoPartner: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure btnSearchClick(Sender: TObject);
    procedure nClearHardinfoClick(Sender: TObject);
    procedure nADPartnerClick(Sender: TObject);
    procedure nNoPartnerClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmUser: TfrmUser;

implementation

uses GTMain;

{$R *.dfm}

procedure TfrmUser.FormCreate(Sender: TObject);
begin
  Query.Connection := Database;
  Query.Open;
end;

procedure TfrmUser.btnSearchClick(Sender: TObject);
var
  Condition: string;
begin
  if Trim(edtUserName.Text) <> '' then
    Condition := 'UserName LIKE ''%' + Trim(edtUserName.Text) + '%''';
  if Trim(edtUserId.Text) <> '' then
  begin
    if Condition <> '' then
      Condition := Condition + ' AND ';
    Condition := Format('Usernum = %s', [Trim(edtUserId.Text)]);
  end;
  if Trim(edtIP.Text) <> '' then
  begin
    if Condition <> '' then
      Condition := Condition + ' AND ';
    Condition := Format('UserIp = %s', [Trim(edtIP.Text)]);
  end;
  Query.Filtered := False;
  Query.Filter := Condition;
  Query.Filtered := True;
end;

procedure TfrmUser.nClearHardinfoClick(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to dbgUser.SelectedRows.Count - 1 do
  begin
    with dbgUser.DataSource.DataSet do
    begin
      GotoBookmark(Pointer(dbgUser.SelectedRows[i]));
      Edit;
      FieldByName('UserHardInfo').AsString := '';
      CheckBrowseMode;
    end;
  end;
end;

procedure TfrmUser.nADPartnerClick(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to dbgUser.SelectedRows.Count - 1 do
  begin
    with dbgUser.DataSource.DataSet do
    begin
      GotoBookmark(Pointer(dbgUser.SelectedRows[i]));
      Edit;
      FieldByName('UserADPartner').Value := 1;
      CheckBrowseMode;
    end;
  end;
end;

procedure TfrmUser.nNoPartnerClick(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to dbgUser.SelectedRows.Count - 1 do
  begin
    with dbgUser.DataSource.DataSet do
    begin
      GotoBookmark(Pointer(dbgUser.SelectedRows[i]));
      Edit;
      FieldByName('UserADPartner').Value := 0;
      CheckBrowseMode;
    end;
  end;
end;

end.
